package pers.cfeng.common;

import lombok.Getter;
import lombok.Setter;

/**
 * @author Cfeng
 * 自定义抛出所有异常
 */

@Getter
@Setter
public class DatabaseException extends RuntimeException {
    public String code;
    public String message;
    private boolean useCode; //是否使用ErrorCode码

    public DatabaseException(String code, String message) {
        super(message);
        this.code = code;
        this.message = message;
        this.useCode = false;
    }

    public DatabaseException(String code, String message, boolean useCode) {
        super(message);
        this.code = code;
        this.message = message;
        this.useCode = useCode;
    }

    public DatabaseException(String message) {
        super(message);
        this.message = message;
    }

    public DatabaseException(Throwable cause) {
        super(cause);
    }

    public DatabaseException(ErrorCode errorCode) {
        this(errorCode, errorCode.getMessage());
    }

    public DatabaseException(ErrorCode errorCode, boolean useCode) {
        this(errorCode, errorCode.getMessage(), useCode);
    }

    public DatabaseException(ErrorCode errorCode, String message) {
        this(errorCode, message, true);
    }

    public DatabaseException(ErrorCode errorCode, String message, boolean userCode) {
        super(message);
        this.code = errorCode.getCode();
        this.message = message;
        this.useCode = userCode;
    }
}
